using Newtonsoft.Json;
using System.IO;

public static class JsonUtil
{
    public static string JsonSerializer(this string str)
    {
        JsonSerializer jsonSerializer = new JsonSerializer();
        TextReader textReader = new StringReader(str);
        JsonTextReader jtr = new JsonTextReader(textReader);
        object obj = jsonSerializer.Deserialize(jtr);
        if (obj != null)
        {
            StringWriter stringWriter = new StringWriter();
            JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented,
                Indentation = 4,
                IndentChar = ' '
            };
            jsonSerializer.Serialize(stringWriter, obj);
            return stringWriter.ToString();
        }
        else
        {
            return str;
        }

    }
}
